<?php
/*
 * @description: Модель для работы с Оценками
 * @copyright Copyright (c) 2012-2017 Marin V. , Tykva A. , Kozel R. , Sokolov D.
 * @version 1.0
 * @link http://lecturebox.ru
*/

class Model_Rank
{

    protected $_dbTable;
    protected $_row;
    
    public function __construct($id=0)
    {

        $this->_dbTable = new Model_DbTable_Ranked();
        if($id)
            $this->_row = $this->_dbTable->find($id)->current();
        else
            $this->_row = $this->_dbTable->createRow();
    }

        
    public function getAll()
    {   
        return $this->_row = $this->_dbTable->fetchAll();
    }
    
    // не уверен зачем написал
    public function getRankByLectureId($lecture_id)
    {   
        $select = $this->_dbTable->select();
        $select->where('lecture_id = ?', $lecture_id);
        return $this->_row = $this->_dbTable->fetchAll($select);
    }
    public function RanksByLectureId($lecture_id)
    {   
        $select = $this->_dbTable->select();
        $select->where('lecture_id = ?', $lecture_id);
        $this->_row = $this->_dbTable->fetchAll($select);
    }
    
    public function ifUserRankVideo($lecture_id,$user_id)
    {   
        $select = $this->_dbTable->select();
        $select->where('lecture_id = ?', $lecture_id)
                ->where('user_id =?',$user_id);
        return $this->_row = $this->_dbTable->fetchAll($select);
    }
    
    public function save()
    {
        $this->_row->save();
    }
    
    public function delete()
    {
        $this->_row->delete();
    }
    
    public function __set($name, $val)
    {
        if (isset($this->_row->$name)) {
            $this->_row->$name = $val;
        }
    }

    public function __get($name)
    {
        if (isset($this->_row->$name)) {
            return $this->_row->$name;
        }
    }
 
}
